#pragma once

#include "vision_global.h"
#include <QObject>

#include <opencv2/opencv.hpp>

#include "HalconCpp.h"
using namespace HalconCpp;

class VISION_EXPORT Calibration_NinePoint :
    public QObject
{
    Q_OBJECT
public:
    // 标定函数
    double calibration();

    void clearDatas();

    // 计算目标在机器人坐标系下坐标
    cv::Point2d affineTransToRobot(double px, double py);
    bool affineTransToRobot(double px, double py, double* rx, double* ry);

    cv::Point2d getObjImagePos() { return image_pos; }
    // 返回变换后的坐标位置
    cv::Point2d getObjRobotPos() { return robot_pos; }

    void addPoint_pixel(double x, double y);
    void addPoint_robot(double x, double y);

    void writeTransFile(std::string fileName);
    void readTransFile(std::string fileName);
private:
    // 标定坐标点
    // 像素坐标点
    HTuple rows_py;
    HTuple cols_px;
    // 机械手坐标点
    HTuple rows_Ry;
    HTuple cols_Rx;

    // 实际坐标位置：转换后物体在机器人坐标系坐标
    HTuple robot_row;
    HTuple robot_col;

    cv::Point2d image_pos;
    cv::Point2d robot_pos;

    // 标定得到变换矩阵：先保存到文件，然后读取
    HTuple trans_;
};

